package ae.pcfc.etks.online.web.controller.user.internal.workflow;

/* $Id: ClientCompanyController.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 * April 11, 2011 	Mohtisham.Salahria	Created
 *
 */


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import ae.pcfc.etks.online.web.PageType;
import ae.pcfc.etks.online.web.ViewPath;
import ae.pcfc.etks.online.web.ViewUtils;
import ae.pcfc.etks.online.web.controller.BaseController;
import ae.pcfc.etks.online.web.util.SecurityUtils;


@Controller
@RequestMapping(ViewPath.ADMIN_REDIRECT_WORKFLOW)
public class WorkflowRedirectController extends BaseController{
	
	
	private Map<String, String> propertyConstants;

	@Resource(name = "propertyConstants")
	public void setPropertyConstants(Map<String, String> propertyConstants) {
		this.propertyConstants = propertyConstants;
	}

	
	private String nonClientCompanyRegistrationProcessCode;
	private String clientCompanyRegistrationProcessCode;
	private String nonClientPersonRegistrationProcessCode;
	private String clientPersonRegistrationProcessCode;	
	private String serviceRegistrationProcessCode;
	private String clientRoleRequestProcessCode;
	
	
	public String getNonClientCompanyRegistrationProcessCode() {
		return nonClientCompanyRegistrationProcessCode;
	}
	@Value("${nonClientCompanyRegistrationProcessCode}")
	public void setNonClientCompanyRegistrationProcessCode(
			String nonClientCompanyRegistrationProcessCode) {
		this.nonClientCompanyRegistrationProcessCode = propertyConstants.get("nonClientCompanyRegistrationProcessCode");
	}


	public String getClientCompanyRegistrationProcessCode() {
		return clientCompanyRegistrationProcessCode;
	}

	@Value("${clientCompanyRegistrationProcessCode}")
	public void setClientCompanyRegistrationProcessCode(
			String clientCompanyRegistrationProcessCode) {
		this.clientCompanyRegistrationProcessCode = propertyConstants.get("clientCompanyRegistrationProcessCode");
	}


	public String getNonClientPersonRegistrationProcessCode() {
		return nonClientPersonRegistrationProcessCode;
	}

	@Value("${nonClientPersonRegistrationProcessCode}")
	public void setNonClientPersonRegistrationProcessCode(
			String nonClientPersonRegistrationProcessCode) {
		this.nonClientPersonRegistrationProcessCode = propertyConstants.get("nonClientPersonRegistrationProcessCode");
	}


	public String getClientPersonRegistrationProcessCode() {
		return clientPersonRegistrationProcessCode;
	}

	@Value("${clientPersonRegistrationProcessCode}")
	public void setClientPersonRegistrationProcessCode(
			String clientPersonRegistrationProcessCode) {
		this.clientPersonRegistrationProcessCode = propertyConstants.get("clientPersonRegistrationProcessCode");
	}


	public String getServiceRegistrationProcessCode() {
		return serviceRegistrationProcessCode;
	}

	@Value("${serviceRegistrationProcessCode}")
	public void setServiceRegistrationProcessCode(
			String serviceRegistrationProcessCode) {
		this.serviceRegistrationProcessCode = propertyConstants.get("serviceRegistrationProcessCode");
	}


	public String getClientRoleRequestProcessCode() {
		return clientRoleRequestProcessCode;
	}

	@Value("${clientRoleRequestProcessCode}")
	public void setClientRoleRequestProcessCode(String clientRoleRequestProcessCode) {
		this.clientRoleRequestProcessCode = clientRoleRequestProcessCode;
	}


	@RequestMapping(value = "/form.htm", method = RequestMethod.GET)
	public String redirect(HttpServletRequest request,
    		@RequestParam(value = "appid", required = true) String appid,
    		@RequestParam(value = "Incident", required = true) String incident,
    		@RequestParam(value = "StepName", required = true) String stepName,
    		@RequestParam(value = "ProcessCode", required = true) String processCode) {
		Map<String,String> redirectParams = new HashMap<String, String>();
		redirectParams.put("appid", SecurityUtils.encrypt(appid));
		redirectParams.put("Incident", SecurityUtils.encrypt(incident));
		redirectParams.put("StepName", SecurityUtils.encrypt(stepName));
		if(StringUtils.isNotBlank(processCode) &&  processCode.equals(nonClientCompanyRegistrationProcessCode)){
			return ViewUtils.getRedirect(ViewPath.ADMIN_GENERAL_COMPANY_REQUEST_NON_CLIENT, PageType.FORM, redirectParams);
		}else if(StringUtils.isNotBlank(processCode) &&  processCode.equals(clientCompanyRegistrationProcessCode)){
			return ViewUtils.getRedirect(ViewPath.ADMIN_GENERAL_COMPANY_REQUEST_CLIENT, PageType.FORM, redirectParams);
		}else if(StringUtils.isNotBlank(processCode) &&  processCode.equals(nonClientPersonRegistrationProcessCode)){
			return ViewUtils.getRedirect(ViewPath.ADMIN_GENERAL_PERSON_REQUEST_NON_CLIENT, PageType.FORM, redirectParams);
		}else if(StringUtils.isNotBlank(processCode) &&  processCode.equals(clientPersonRegistrationProcessCode)){
			return ViewUtils.getRedirect(ViewPath.ADMIN_GENERAL_PERSON_REQUEST_CLIENT, PageType.FORM, redirectParams);
		}else if(StringUtils.isNotBlank(processCode) &&  processCode.equals(serviceRegistrationProcessCode)){
			return ViewUtils.getRedirect(ViewPath.ADMIN_GENERAL_SERVICE_REQUEST, PageType.FORM, redirectParams);
		}else if(StringUtils.isNotBlank(processCode) &&  processCode.equals(clientRoleRequestProcessCode)){
			return ViewUtils.getRedirect(ViewPath.ADMIN_GENERAL_ROLE_REQUEST, PageType.FORM, redirectParams);
		}else{
			return ViewUtils.DEFAULT_VIEW;
		}
	}
	
}


	


